
#include "HttpCmdGetShellResult.h"
#include "SysHelper.h"


CHttpCmdGetShellResult::CHttpCmdGetShellResult()
{ 
    ClearCmdLocalData();
}

CHttpCmdGetShellResult::~CHttpCmdGetShellResult()
{

}

bool CHttpCmdGetShellResult::CheckParamVaild(const std::string &strReqMessage)
{
    // printf("CHttpCmdGetShellResult::CheckParamVaild() strReqMessage = %s\n", strReqMessage.c_str());
    // printf("===============\n");
    if(strReqMessage.empty())
    {
        return false;
    }
    return ParseParamDataToSave(strReqMessage);
}

bool CHttpCmdGetShellResult::FillRspData(std::string &strRspData)
{
    std::string strResultData;
    CSysHelper::GetShellReturn(m_strShellCmd, strResultData);

    // need some system helper functions
    neb::CJsonObject rspJsonObj;
    rspJsonObj.AddEmptySubObject("Data");
    neb::CJsonObject &dataJsonObj = rspJsonObj["Data"];

    dataJsonObj.Add("Shell Result", strResultData);


    strRspData = rspJsonObj.ToString();
}

void CHttpCmdGetShellResult::ClearCmdLocalData()
{
    m_strShellCmd.clear();
    return ;
}

bool CHttpCmdGetShellResult::ParseParamDataToSave(const std::string &strReqMessage)
{
    neb::CJsonObject reqJsonObj(strReqMessage);
    neb::CJsonObject &dataJsonObj = reqJsonObj["Data"];

    // These Args are optional
    dataJsonObj.Get("Cmd", m_strShellCmd);


    return true;
}
